<html>
<head><meta charset="utf-8"><title>Mask API · project-portable-simd · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/index.html">project-portable-simd</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html">Mask API</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218943663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/218943663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#218943663">(Dec 05 2020 at 17:10)</a>:</h4>
<p>So, I've been thinking more about masks and something hasn't been sitting quite right with me.  We took the <code>m8</code> etc types by default from packed_simd, but maybe they shouldn't exist at all?  I couldn't find a compelling reason why <code>m8x8</code> should implement <code>AsRef&lt;[m8]&gt;</code> rather than just provide functions for converting to and from <code>u8x8</code> in addition to the <code>set</code> and <code>test</code> functions that all masks have.</p>



<a name="218943724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/218943724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#218943724">(Dec 05 2020 at 17:11)</a>:</h4>
<p>I think this would simplify the interface quite a bit.  All of the scalar mask types can be removed, and the full width and single bit width masks would have identical interfaces, except they would have different conversion functions/trait implementations.</p>



<a name="218943839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/218943839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#218943839">(Dec 05 2020 at 17:14)</a>:</h4>
<p>If for some reason you absolutely need to mutate the mask vector by slice rather than with the <code>set</code> function it would require unsafe or an additional check, but I really don't see why you would need to insist on using a slice in the first place.</p>



<a name="218943851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/218943851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#218943851">(Dec 05 2020 at 17:14)</a>:</h4>
<p>Anyone have any thoughts?</p>



<a name="218965436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/218965436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#218965436">(Dec 06 2020 at 02:51)</a>:</h4>
<p>Yeah, that sounds good. Any way to make masks do less means that it's also easier to figure out what they can be used for.</p>



<a name="219032551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219032551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219032551">(Dec 07 2020 at 00:41)</a>:</h4>
<p><span class="user-mention" data-user-id="312331">@Caleb Zulawski</span> This sounds good to me so far since it simplifies everything. Sounds pretty different from where stdsimd#44 is at right now though. Should we start with a new PR or merge stdsimd#44 for now and then build that PR on top of master?</p>



<a name="219032613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219032613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219032613">(Dec 07 2020 at 00:43)</a>:</h4>
<p>I rebased my const generic branch off of that PR so we can just hold off and review the final product</p>



<a name="219032671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219032671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219032671">(Dec 07 2020 at 00:44)</a>:</h4>
<p>It'll probably be a pretty significant reduction in API between the const generics and removing the extra mask types</p>



<a name="219032673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219032673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219032673">(Dec 07 2020 at 00:44)</a>:</h4>
<p>(and therefore hopefully easier to review?)</p>



<a name="219159678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219159678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219159678">(Dec 08 2020 at 01:01)</a>:</h4>
<p>hopefully!</p>



<a name="219162124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219162124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219162124">(Dec 08 2020 at 01:44)</a>:</h4>
<p><span class="user-mention" data-user-id="229517">@Jacob Lifshay</span> what types of registers do the RISC-V masks use?  And can you have more than say 128 lanes?  I'm trying to figure out the appropriate datatype for the single bit masks (most compilers seem to just use plain integers for AVX-512's masks)</p>



<a name="219166875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219166875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219166875">(Dec 08 2020 at 03:12)</a>:</h4>
<p><span class="user-mention" data-user-id="312331">@Caleb Zulawski</span>  <a href="https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc">https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc</a></p>
<blockquote>
<p>A vector mask occupies only one vector register regardless of SEW and LMUL. Each element is allocated a single mask bit in a mask vector register.</p>
</blockquote>
<blockquote>
<p>Comparison operations that set a mask register are also implicitly a narrowing operation.</p>
</blockquote>



<a name="219167381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219167381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219167381">(Dec 08 2020 at 03:22)</a>:</h4>
<p>Oh interesting</p>



<a name="219167388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219167388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219167388">(Dec 08 2020 at 03:22)</a>:</h4>
<p>Okay that confirms my suspicions though. They can be extremely wide</p>



<a name="219167667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219167667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219167667">(Dec 08 2020 at 03:29)</a>:</h4>
<p>VLEN = 2^N where N &gt;= 7.<br>
ELEN = 2^N where N &gt;= 3.</p>
<p>XLEN must fit this value: The XLEN-bit-wide read-only CSR vlenb holds the value VLEN/8, i.e., the vector register length in bytes.</p>
<blockquote>
<p>In base V extension, only data elements widths up to max(XLEN,FLEN) must be supported.</p>
</blockquote>
<blockquote>
<p>In base V extension, only index widths up to XLEN must be supported.</p>
</blockquote>
<blockquote>
<p>RV128 will require index EEW of 128.</p>
</blockquote>



<a name="219167994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219167994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219167994">(Dec 08 2020 at 03:37)</a>:</h4>
<p>I'm... confused</p>



<a name="219168074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219168074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219168074">(Dec 08 2020 at 03:39)</a>:</h4>
<p>...sorry, was trying to see if I could take enough notes that I could easily pin down a fatness for mask lengths without pulling out a full-blown SAT solver, heh.</p>



<a name="219168084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219168084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219168084">(Dec 08 2020 at 03:39)</a>:</h4>
<p>Lol</p>



<a name="219168156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219168156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219168156">(Dec 08 2020 at 03:41)</a>:</h4>
<p>If a mask is a whole vector register that's a little different than the AVX mask registers which are small</p>



<a name="219168172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219168172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219168172">(Dec 08 2020 at 03:41)</a>:</h4>
<p>Though I wonder if LLVM would optimize to the same thing regardless of memory layout</p>



<a name="219168218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219168218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219168218">(Dec 08 2020 at 03:42)</a>:</h4>
<p>It would actually be much better code if we could just say the masks take a whole vector register even on AVX512</p>



<a name="219168236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219168236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219168236">(Dec 08 2020 at 03:42)</a>:</h4>
<p>And leave the upper bits 0</p>



<a name="219268259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219268259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219268259">(Dec 08 2020 at 21:53)</a>:</h4>
<p>I mean... why not?</p>



<a name="219268386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219268386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219268386">(Dec 08 2020 at 21:54)</a>:</h4>
<p>Also this actually implicitly says something about RISCVV that I didn't notice before!</p>



<a name="219268496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219268496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219268496">(Dec 08 2020 at 21:55)</a>:</h4>
<p>a vector mask must fit in a vector register, so you can't mask anything bigger than VLEN, so you <em>cannot</em> have  more than VLEN elements in a vector and also do a masking operation which means <em>in practice</em> VLEN is a cap on vector element count.</p>



<a name="219271093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219271093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219271093">(Dec 08 2020 at 22:18)</a>:</h4>
<p>So maybe I'm confused, but since you can't have an element smaller than 1 bit, isn't that a given?</p>



<a name="219271156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219271156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219271156">(Dec 08 2020 at 22:19)</a>:</h4>
<p>Or is vlen simply a _minimum_ vector length?</p>



<a name="219271187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219271187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219271187">(Dec 08 2020 at 22:19)</a>:</h4>
<p>(one of these days I'll learn how zulip formatting works...)</p>



<a name="219271361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219271361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219271361">(Dec 08 2020 at 22:21)</a>:</h4>
<p><span class="user-mention" data-user-id="312331">@Caleb Zulawski</span> well the entire point of RISCV-V's design is it lets you have "vectors" that occupy multiple vector registers, so that the code can be relatively hardware-agnostic. I  don't fully understand all the details yet.</p>



<a name="219271484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219271484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219271484">(Dec 08 2020 at 22:22)</a>:</h4>
<p>What I was suggesting is that typical avx512 implementations use say i16 for __mmask16, but we may be able to avoid a slew of issues by using u8x16, even if it's wasteful</p>



<a name="219271512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219271512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219271512">(Dec 08 2020 at 22:22)</a>:</h4>
<p>(and hope that the optimizer chooses to ignore the wasted bits)</p>



<a name="219271565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219271565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219271565">(Dec 08 2020 at 22:23)</a>:</h4>
<p>This is at least partially motivated by const generics</p>



<a name="219272017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272017">(Dec 08 2020 at 22:27)</a>:</h4>
<p>what kind of issues are we avoiding? but after our experiences so far I am definitely very game for "pray to LLVM-kun to optimize our code correctly".</p>



<a name="219272048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272048">(Dec 08 2020 at 22:27)</a>:</h4>
<p>So one that's not const generic specific is layout</p>



<a name="219272117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272117">(Dec 08 2020 at 22:28)</a>:</h4>
<p>It's probably not meaningful but it would be very convenient if they were the same type</p>



<a name="219272124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272124">(Dec 08 2020 at 22:28)</a>:</h4>
<p>The two types of masks</p>



<a name="219272194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272194">(Dec 08 2020 at 22:29)</a>:</h4>
<p>Another thing is that for avx512 the masks don't need to be repr(simd) but for other architectures they probably do. So might as well make them all repr(simd)</p>



<a name="219272250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272250">(Dec 08 2020 at 22:29)</a>:</h4>
<p>Yeah, that constraint is on us anyways.</p>



<a name="219272325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272325">(Dec 08 2020 at 22:30)</a>:</h4>
<p>The const generic issue is extremely frustrating, though</p>



<a name="219272329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272329">(Dec 08 2020 at 22:30)</a>:</h4>
<p>So</p>



<a name="219272371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272371">(Dec 08 2020 at 22:31)</a>:</h4>
<p>You can do this just fine:</p>
<div class="codehilite"><pre><span></span><code>#[repr(simd)]
pub struct SimdU8&lt;const LANES: usize&gt;([u8; LANES]);
</code></pre></div>



<a name="219272530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272530">(Dec 08 2020 at 22:32)</a>:</h4>
<p>But to make a bitmask you need to do this:</p>
<div class="codehilite"><pre><span></span><code>#[repr(simd)]
pub struct SimdBitMask&lt;const LANES: usize&gt;([u8; (LANES + 7) / 8]) where [(); (LANES + 7) / 8]: Sized;
</code></pre></div>



<a name="219272576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272576">(Dec 08 2020 at 22:32)</a>:</h4>
<p>...lol.</p>



<a name="219272581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272581">(Dec 08 2020 at 22:32)</a>:</h4>
<p>Supposedly the bound syntax will be cleaned up at some point (once const generic bounds become a thing)</p>



<a name="219272630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272630">(Dec 08 2020 at 22:33)</a>:</h4>
<p>But regardless, you have a bound because it basically needs to ensure that your anonymous const actually evaluates and doesn't overflow or something</p>



<a name="219272675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272675">(Dec 08 2020 at 22:33)</a>:</h4>
<p>You can of course make the variable the number of bytes instead of the number of lanes, but that just moves the bound to somewhere else</p>



<a name="219272716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272716">(Dec 08 2020 at 22:34)</a>:</h4>
<p>right.</p>



<a name="219272745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272745">(Dec 08 2020 at 22:34)</a>:</h4>
<p>unfortunately that would mean our "opaque" mask type would also have the bound on it</p>



<a name="219272793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272793">(Dec 08 2020 at 22:35)</a>:</h4>
<p>I think if the situation ever improved in the future we would reserve the right to change the layout and remove the extra bytes</p>



<a name="219272797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272797">(Dec 08 2020 at 22:35)</a>:</h4>
<p>and that bound would infect everywhere it is used</p>



<a name="219272801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272801">(Dec 08 2020 at 22:35)</a>:</h4>
<p>yep.</p>



<a name="219272839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272839">(Dec 08 2020 at 22:35)</a>:</h4>
<p>can we type alias that bound by any chance</p>



<a name="219272885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272885">(Dec 08 2020 at 22:36)</a>:</h4>
<p>bound alias</p>



<a name="219272890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272890">(Dec 08 2020 at 22:36)</a>:</h4>
<p>yeah, you can do</p>



<a name="219272892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272892">(Dec 08 2020 at 22:36)</a>:</h4>
<p>traitify it</p>



<a name="219272898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219272898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219272898">(Dec 08 2020 at 22:36)</a>:</h4>
<p>aha.</p>



<a name="219273069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219273069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219273069">(Dec 08 2020 at 22:37)</a>:</h4>
<div class="codehilite"><pre><span></span><code>const fn valid_lanes(lanes: usize) { (lanes + 7 / 8) }
struct SimdBitmask&lt;const LANES: usize&gt;([u8; valid_lanes(LANES)]) where [(); valid_lanes(LANES)]: Sized;
</code></pre></div>



<a name="219273148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219273148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219273148">(Dec 08 2020 at 22:38)</a>:</h4>
<p>maybe something slightly better than that</p>



<a name="219273177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219273177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219273177">(Dec 08 2020 at 22:38)</a>:</h4>
<p>but i'm not thrilled about</p>
<ul>
<li>such a hacky bound</li>
<li>having a bound at all</li>
</ul>



<a name="219273229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219273229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219273229">(Dec 08 2020 at 22:39)</a>:</h4>
<p>mhm...</p>



<a name="219273239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219273239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219273239">(Dec 08 2020 at 22:39)</a>:</h4>
<p>Maybe we need a language extension of some sort (which would be unfortunate) but this is basically C++'s <code>std::bitset</code></p>



<a name="219273694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219273694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219273694">(Dec 08 2020 at 22:44)</a>:</h4>
<p>Not sure if it's even possible, but this would also be solved with a <code>u1</code> type that was allowed to pack sub-byte-width <span aria-label="smiling devil" class="emoji emoji-1f608" role="img" title="smiling devil">:smiling_devil:</span></p>



<a name="219273810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219273810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219273810">(Dec 08 2020 at 22:45)</a>:</h4>
<p>so <a href="https://crates.io/crates/bitvec">https://crates.io/crates/bitvec</a></p>



<a name="219274336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219274336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219274336">(Dec 08 2020 at 22:51)</a>:</h4>
<p><span class="user-mention" data-user-id="312331">@Caleb Zulawski</span>  I believe imposing a bound of either usize or VLEN on masks is fine for the condition of shipping core::simd on nightly. I believe we won't find a good answer for this problem before we get our code into nightly.</p>



<a name="219274502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219274502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219274502">(Dec 08 2020 at 22:53)</a>:</h4>
<p>( using VLEN the same way RISCV-V does, here... as the actual size of a vector register's state. )</p>



<a name="219274949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219274949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219274949">(Dec 08 2020 at 22:58)</a>:</h4>
<p>Yeah, just like bitvec, except I think that would have the same problems with bounds as we're seeing here</p>



<a name="219275016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219275016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219275016">(Dec 08 2020 at 22:59)</a>:</h4>
<p>So we can impose a bound by making separate types for each bit width, but I'm still not sure that's what we want</p>



<a name="219275115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219275115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219275115">(Dec 08 2020 at 23:00)</a>:</h4>
<p>It would be nice if we could somehow prove to the compiler our const fn will never fail so the bound can be removed</p>



<a name="219275333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219275333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219275333">(Dec 08 2020 at 23:02)</a>:</h4>
<p>yeah, basically my feeling is we should just do whatever ships right now and then punt this to a discussion with the const generics folks about how to make it happen.</p>



<a name="219275387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219275387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219275387">(Dec 08 2020 at 23:03)</a>:</h4>
<p>That would be skipping bit masks <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="219275394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219275394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219275394">(Dec 08 2020 at 23:03)</a>:</h4>
<p>Which is probably fine</p>



<a name="219275473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219275473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219275473">(Dec 08 2020 at 23:04)</a>:</h4>
<p>I agree we should probably bring it up with them</p>



<a name="219275638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219275638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219275638">(Dec 08 2020 at 23:06)</a>:</h4>
<p>Fine With Me, right now!<br>
I was previously anxious about deprioritizing things too early but I don't think that's actually a concern anymore.</p>



<a name="219275692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219275692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219275692">(Dec 08 2020 at 23:07)</a>:</h4>
<p>I think as long as we address them and don't rule them out we're in good shape</p>



<a name="219395793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219395793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219395793">(Dec 09 2020 at 20:50)</a>:</h4>
<p>So I realized something potentially evil we can do.  Should we extend #[repr(simd)] to support i1xN vectors?  I think we can make the argument that i1 is much more relevant in SIMD than elsewhere so it doesn't need a broader implementation</p>



<a name="219397707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219397707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219397707">(Dec 09 2020 at 21:05)</a>:</h4>
<p>There's <a href="https://github.com/rust-lang/rfcs/pull/2581#issuecomment-439966415">some level of lang support for more integer widths</a>, so it might not be all that evil.</p>



<a name="219400461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219400461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219400461">(Dec 09 2020 at 21:26)</a>:</h4>
<p>Maybe I'm wrong, but that comment seems to indicate there isn't any support yet?</p>



<a name="219403007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219403007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219403007">(Dec 09 2020 at 21:45)</a>:</h4>
<p>Not for that RFC as-is, but in a vague sense of "it doesn't need to just be library; there can be language semantic changes from these things too"</p>



<a name="219403142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219403142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219403142">(Dec 09 2020 at 21:46)</a>:</h4>
<p>Though I guess you might be able to get pretty far with <code>#[repr(u8)] enum Mask { Zero = 0, All = 0xFF }</code> or whatever...</p>



<a name="219412600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219412600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219412600">(Dec 09 2020 at 23:03)</a>:</h4>
<p><code>i1xN</code> sounds like a good plan to me! If we do it right, we could have:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">i1</span><span class="p">(</span><span class="kt">bool</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>where <code>#[repr(simd)]</code> treats <code>i1</code> specially, changing the layout to a bit-vector such that you can read or write array elements but can't take their address. when not in <code>#[repr(simd)]</code>, <code>i1</code> is otherwise a normal struct most likely with <code>bool</code>'s layout.</p>



<a name="219412755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219412755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219412755">(Dec 09 2020 at 23:05)</a>:</h4>
<p>this should be compatible with future bitfields support, assuming those need a <code>#[repr(bitpacked)]</code> or similar.</p>



<a name="219413106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219413106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219413106">(Dec 09 2020 at 23:08)</a>:</h4>
<p>if there's a future <code>i1</code> built-in integer type, that would replace the <code>struct i1</code> type.</p>



<a name="219414101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219414101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219414101">(Dec 09 2020 at 23:20)</a>:</h4>
<p><code>#[repr(simd)]</code> could also directly handle <code>bool</code> as <code>i1</code>.</p>



<a name="219415247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219415247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219415247">(Dec 09 2020 at 23:36)</a>:</h4>
<p>Yeah, that's more along the lines of what I was thinking of, since it doesn't require significant changes</p>



<a name="219415355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219415355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219415355">(Dec 09 2020 at 23:37)</a>:</h4>
<p>A problem I see, though, is you couldn't really access the fields and would probably require a lot of special casing that</p>



<a name="219419157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219419157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219419157">(Dec 10 2020 at 00:29)</a>:</h4>
<p>If we do support bitmasks using:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[derive(Copy, Clone)]</span><span class="w"></span>
<span class="cp">#[repr(simd)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">i1x8</span><span class="p">([</span><span class="kt">bool</span><span class="p">;</span><span class="w"> </span><span class="mi">8</span><span class="p">]);</span><span class="w"></span>
</code></pre></div>
<p>I would expect the compiler to gain support (perhaps using simd intrinsics instead) for:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">b</span>: <span class="kt">bool</span> <span class="o">=</span><span class="w"> </span><span class="o">..</span><span class="p">.;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">ba</span>: <span class="p">[</span><span class="kt">bool</span><span class="p">;</span><span class="w"> </span><span class="mi">8</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">..</span><span class="p">.;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">bv</span>: <span class="nc">i1x8</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">..</span><span class="p">.;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">i</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="o">..</span><span class="p">.;</span><span class="w"></span>
<span class="n">bv</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">i1x8</span><span class="p">(</span><span class="n">ba</span><span class="p">);</span><span class="w"> </span><span class="c1">// convert to bit-vector</span>
<span class="n">bv</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">i1x8</span><span class="p">([</span><span class="n">b</span><span class="p">;</span><span class="w"> </span><span class="mi">8</span><span class="p">]);</span><span class="w"> </span><span class="c1">// splat (can fall back to convert to bit-vector)</span>
<span class="n">ba</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bv</span><span class="p">.</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="c1">// convert from bit-vector</span>
<span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bv</span><span class="p">.</span><span class="mi">0</span><span class="p">[</span><span class="n">i</span><span class="p">];</span><span class="w"> </span><span class="c1">// read element</span>
<span class="n">bv</span><span class="p">.</span><span class="mi">0</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="p">;</span><span class="w"> </span><span class="c1">// write element</span>
</code></pre></div>
<p>All fallback implementations of mask ops can be implemented in terms of those ops.</p>



<a name="219427549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219427549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219427549">(Dec 10 2020 at 03:09)</a>:</h4>
<p>in <a href="#narrow/stream/260443-project-const-generics/topic/const_evaluatable_checked.20bound.20repetition">https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/const_evaluatable_checked.20bound.20repetition</a> i mentioned the issue around the bounds in const_evaluable_checked being an abstraction leak in annoying ways.</p>
<p>also the issue with i1 was terrible codegen universally as soon as everything stopped being inlined (because the compiler will spill it to an actual bool array, which isn't how anything works)</p>



<a name="219427740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219427740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219427740">(Dec 10 2020 at 03:14)</a>:</h4>
<p>#[repr(simd)] may fix that because it passes things by reference. We may also be able to explicitly cast it so it's packed</p>



<a name="219427750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219427750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219427750">(Dec 10 2020 at 03:15)</a>:</h4>
<p>heh, should I link lcnr to <a href="https://github.com/rust-lang/stdsimd/issues/50">https://github.com/rust-lang/stdsimd/issues/50</a> there, then?</p>



<a name="219427852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219427852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219427852">(Dec 10 2020 at 03:17)</a>:</h4>
<p>Maybe lol</p>



<a name="219428006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219428006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219428006">(Dec 10 2020 at 03:20)</a>:</h4>
<p><span class="user-mention" data-user-id="312331">@Caleb Zulawski</span> not sure why passing things by reference would make any difference at all here... That actually sounds much worse. The issue is that the vector types can't stay abstract forever. At the end of the day llvm/rustc needs to know what they layout of these masks are in situations like when they're in memory/on the stack, or passed/returned via from/to a function which the def can't be seen... and with &lt;i1 x N&gt;  the answer is "it's basically a complete disaster".</p>



<a name="219428302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219428302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219428302">(Dec 10 2020 at 03:27)</a>:</h4>
<p><span class="user-mention" data-user-id="209168">@Thom Chiovoloni</span> looking at some llvm bugs, the problem only seems to really come up when using GEP?  We will need to make sure to do actual bit accesses on packed vectors. Which maybe means we should store them as u8 arrays in rust but lower the simd ops to i1 with bitcast (and definitely don't use GEP!)</p>



<a name="219428383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219428383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219428383">(Dec 10 2020 at 03:30)</a>:</h4>
<p><span class="user-mention" data-user-id="312331">@Caleb Zulawski</span> the example from the last time we had this debate was <a href="https://gcc.godbolt.org/z/qbEzv5">https://gcc.godbolt.org/z/qbEzv5</a>. I don't even really think it's an LLVM bug. This is exactly what I'd expect LLVM (or any compiler backend) to do here.</p>



<a name="219428504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219428504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219428504">(Dec 10 2020 at 03:32)</a>:</h4>
<p>recur("aw shit here we go again")</p>



<a name="219428596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219428596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219428596">(Dec 10 2020 at 03:34)</a>:</h4>
<p>Ok. I remember this example.  So I don't think it's quite the same debate as we were having before.  Before we were discussing whether we could always use the i1 type, I think</p>



<a name="219428625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219428625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219428625">(Dec 10 2020 at 03:35)</a>:</h4>
<p>note that that example is just as bad on every arch, and what you should be looking at is the difference between <code>f_sse_inlined</code> and everything else. basically, going from an <code>&lt;i1 x N&gt;</code> to the actual mask type needed for any intrinsics a very difficult operation.</p>
<p>If we could convince LLVM to that the concrete representation of <code>&lt;i1 x N&gt;</code> (when one is needed) should actually be something other than <code>[bool; N]</code> that'd be one thing, but I don't expect that to be feasible for many reasons. For one, the right representations for most current vector ISAs will depend on what produces/consumes the mask — that's why there's both <code>N</code> and <code>M</code> in <code>mNxM</code>.</p>



<a name="219428755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219428755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219428755">(Dec 10 2020 at 03:39)</a>:</h4>
<p>Hmm, I see the difference here. Just... please don't go with a  design that is clean but compiles to terrible code on common arches as soon as the program becomes too big for the compiler to see all at once.</p>



<a name="219428830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219428830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219428830">(Dec 10 2020 at 03:40)</a>:</h4>
<p>I wouldn't want to do anything that compiles to absolute garbage, but I want to at least see the tradeoffs of different things, and those tradeoffs are a bit less clear at the current moment.</p>



<a name="219428858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219428858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219428858">(Dec 10 2020 at 03:41)</a>:</h4>
<p>So, I'm both bad at LLVM IR and ASM, but this looks to me like it's correct? <a href="https://gcc.godbolt.org/z/M4Eqrh">https://gcc.godbolt.org/z/M4Eqrh</a></p>



<a name="219428923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219428923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219428923">(Dec 10 2020 at 03:42)</a>:</h4>
<p>I'm just hazarding a guess based on all of the <code>bfi</code> and <code>ubfx</code> instructions that it's unpacking it to a NEON vector</p>



<a name="219429088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219429088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219429088">(Dec 10 2020 at 03:46)</a>:</h4>
<p>This is actually part of the reason why I suggested <code>#[repr(simd)]</code> may resolve the problem because then the return type isn't actually a vector, it's a reference to a vector, and I'm guessing i1 doesn't play nice with calling conventions for some reason</p>



<a name="219429481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219429481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219429481">(Dec 10 2020 at 03:55)</a>:</h4>
<p>The reason you're getting tons of junk code is because you're trying to use bitvectors on an ISA that doesn't use bitvectors as the mask type, if you switch it to an ISA that does use bitvectors, the code generation is perfectly fine: <a href="https://gcc.godbolt.org/z/6jfPT8">https://gcc.godbolt.org/z/6jfPT8</a></p>



<a name="219429599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219429599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219429599">(Dec 10 2020 at 03:58)</a>:</h4>
<p><span class="user-mention" data-user-id="229517">@Jacob Lifshay</span> I'm aware of that, that's not the issue I think (the bit vectors should still work on any ISA).  The issue is that Thom's example uses 1 byte per vector element, but mine fixes that and correctly packs them</p>



<a name="219429628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219429628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219429628">(Dec 10 2020 at 03:58)</a>:</h4>
<p>I think we shouldn't be too worried about the code quality when we tell the compiler "I want bitvectors! I don't care, give me bitvectors anyway!", because that's exactly what's happening when we use <code>i1x8</code> instead of <code>m8x8</code> or <code>m32x8</code></p>



<a name="219429648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219429648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219429648">(Dec 10 2020 at 03:59)</a>:</h4>
<p>since the <code>m8x8</code> type is supposed to compile at the rustc level to the optimal mask representation for our ISA.</p>



<a name="219429650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219429650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219429650">(Dec 10 2020 at 03:59)</a>:</h4>
<p>The issue isn't code quality, it was that it was actually using an incorrect in-memory representation</p>



<a name="219429731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219429731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219429731">(Dec 10 2020 at 04:00)</a>:</h4>
<p>However your example shows that yes, the code quality will definitely be much better when bit vectors are actually supported directly :)</p>



<a name="219429811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219429811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219429811">(Dec 10 2020 at 04:02)</a>:</h4>
<p><span class="user-mention silent" data-user-id="229517">Jacob Lifshay</span> <a href="#narrow/stream/257879-project-portable-simd/topic/Mask.20API/near/219429481">said</a>:</p>
<blockquote>
<p>The reason you're getting tons of junk code is because you're trying to use bitvectors on an ISA that doesn't use bitvectors as the mask type, if you switch it to an ISA that does use bitvectors, the code generation is perfectly fine: <a href="https://gcc.godbolt.org/z/6jfPT8">https://gcc.godbolt.org/z/6jfPT8</a></p>
</blockquote>
<p>Uh, that's still terrible, though.</p>



<a name="219429812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219429812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219429812">(Dec 10 2020 at 04:02)</a>:</h4>
<p>Hmm, it looked fine to me, though I didn't read it too closely. Note that if LLVM spills something to memory, it can use any arbitrary type it chooses, it doesn't have to be the exact type we asked for originally, since it could be spilling the temporary part-way through conversion, or something similar</p>



<a name="219429948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219429948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219429948">(Dec 10 2020 at 04:05)</a>:</h4>
<p>Yeah, I think it looks ok to me.  Isn't that the best you're going to get without inlining?</p>



<a name="219429961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219429961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219429961">(Dec 10 2020 at 04:05)</a>:</h4>
<p>Yeah, I'd expect so</p>



<a name="219429971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219429971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219429971">(Dec 10 2020 at 04:05)</a>:</h4>
<p>most of the stuff is required by the ABI</p>



<a name="219430031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430031">(Dec 10 2020 at 04:06)</a>:</h4>
<p>That's by no means perfectly fine — <code>f_sse</code> and <code>f_sse_inlined</code> only differ by whether or not the comparison is inlined. it's not as terrible as on arm, but I'd still consider that a disaster honestly.</p>
<p>It's certainly not even close to what you'd write with manual intrinsics (even if the function isn't inlined), or what we'd have if the code didn't use bitvectors for masks</p>



<a name="219430085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430085">(Dec 10 2020 at 04:07)</a>:</h4>
<p>most of the code is required since none of the <code>zmm</code> registers are callee-save requiring the spills and since masks are apparently treated as integers, requiring passing through <code>eax</code></p>



<a name="219430139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430139">(Dec 10 2020 at 04:08)</a>:</h4>
<p>So, I'd expect it to be almost exactly what you'd get using intrinsics.</p>



<a name="219430207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430207">(Dec 10 2020 at 04:09)</a>:</h4>
<blockquote>
<p>and since masks are apparently treated as integers, requiring passing through eax</p>
</blockquote>
<p>I suspect this means you'd probably stick with vector masks rather than bit masks for this, then</p>



<a name="219430304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430304">(Dec 10 2020 at 04:11)</a>:</h4>
<p>If you're forcing it to come in from an uninlined function, yeah probably</p>



<a name="219430305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430305">(Dec 10 2020 at 04:11)</a>:</h4>
<p>idk, maybe? depends on how much power full masks take over bitmasks, that may cause downclocking.</p>



<a name="219430381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430381">(Dec 10 2020 at 04:12)</a>:</h4>
<p>I do also think this example is extremely contrived.  It does prove that the bit vector masks work in both inlined and non-inlined code!</p>



<a name="219430392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430392">(Dec 10 2020 at 04:12)</a>:</h4>
<p>This calling convention also doesn't match <code>#[repr(simd)]</code>'s so I don't think it's worth really nitpicking it</p>



<a name="219430465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430465">(Dec 10 2020 at 04:14)</a>:</h4>
<p>With the mask vector passed by reference rather than value I'm not sure that it would need to pass through <code>eax</code> like this example</p>



<a name="219430493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430493">(Dec 10 2020 at 04:15)</a>:</h4>
<p>(also I think the non-inlined code will be inherently worse because of that calling convention, but it's a necessary evil)</p>



<a name="219430502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430502">(Dec 10 2020 at 04:15)</a>:</h4>
<p>I'd expect that calling convention to match <code>#[repr(simd)] struct i1x8([bool; 8]);</code> since rustc would translate that to LLVM's <code>&lt;8 x i1&gt;</code> so we'd get the exact same code.</p>



<a name="219430561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430561">(Dec 10 2020 at 04:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/Mask.20API/near/219430465">said</a>:</p>
<blockquote>
<p>With the mask vector passed by reference rather than value I'm not sure that it would need to pass through <code>eax</code> like this example</p>
</blockquote>
<p>passing through <code>eax</code> is almost certainly faster than passing through memory.</p>



<a name="219430577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430577">(Dec 10 2020 at 04:17)</a>:</h4>
<p><code>#[repr(simd)]</code> forces the type to be passed by reference even if it's slower</p>



<a name="219430590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430590">(Dec 10 2020 at 04:18)</a>:</h4>
<p>until rustc's gains support for pass simd by value, you mean</p>



<a name="219430632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430632">(Dec 10 2020 at 04:18)</a>:</h4>
<p>I would expect the calling convention to match <code>#[repr(simd)] struct i1x8(u8)</code> at least</p>



<a name="219430641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430641">(Dec 10 2020 at 04:18)</a>:</h4>
<p>If the code for bitmasks is known to be pretty bad if it requires actually calling a function (which I think is something we should expect to be frequent), then is it worth the substantial increase in the API surface required by supporting the the bitmasks in addition to the other masks? in fully inlined cases it seems likely that the compiler would use the optimal thing anywya, so the whole point of these was to be a win in non-inlined cases, which they aren't.</p>



<a name="219430644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430644">(Dec 10 2020 at 04:18)</a>:</h4>
<p>yeah. is that ever planned? I thought it cannot happen</p>



<a name="219430656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430656">(Dec 10 2020 at 04:19)</a>:</h4>
<p>bit vector masks are necessary because they're the only mask type on some architectures</p>



<a name="219430667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430667">(Dec 10 2020 at 04:19)</a>:</h4>
<p>they will absolutely not be the default on x86-64 though, you will need to opt into a trait to gain access to them</p>



<a name="219430719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430719">(Dec 10 2020 at 04:20)</a>:</h4>
<p>Hm, okay.</p>



<a name="219430727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430727">(Dec 10 2020 at 04:20)</a>:</h4>
<p><span class="user-mention silent" data-user-id="209168">Thom Chiovoloni</span> <a href="#narrow/stream/257879-project-portable-simd/topic/Mask.20API/near/219430641">said</a>:</p>
<blockquote>
<p>If the code for bitmasks is known to be pretty bad if it requires actually calling a function (which I think is something we should expect to be frequent), then is it worth the substantial increase in the API surface required by supporting the the bitmasks in addition to the other masks? in fully inlined cases it seems likely that the compiler would use the optimal thing anywya, so the whole point of these was to be a win in non-inlined cases, which they aren't.</p>
</blockquote>
<p>I thought the whole point of the specifically bitmask API (rather than just the generic API) is that you can efficiently use bitmasks when you need them (rather than a for loop or something), not that bitmasks are always fastest.</p>



<a name="219430729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430729">(Dec 10 2020 at 04:20)</a>:</h4>
<p>I don't think it had anything to do with non-inlined cases?  Other than that was clearly a buggy part of LLVM</p>



<a name="219430742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430742">(Dec 10 2020 at 04:21)</a>:</h4>
<p>Yeah.  There was some desire to use them with SSE for some table lookup tricks.  And there's definitely reasons to want to use them with AVX-512 sometimes as well</p>



<a name="219430752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430752">(Dec 10 2020 at 04:21)</a>:</h4>
<p>But the default will be "full" vector masks for most architectures, since they're better in most cases</p>



<a name="219430882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430882">(Dec 10 2020 at 04:24)</a>:</h4>
<p>maybe there could be a separate avx512 x86 target that uses bitvectors (since those are generally more efficient on avx512) instead of full vector masks? We'd probably also want that on OpenPower for SimpleV, since that also uses bitvectors.</p>



<a name="219430896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430896">(Dec 10 2020 at 04:24)</a>:</h4>
<p>if there's a full separate target, you don't have issues with ABI incompatability</p>



<a name="219430909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430909">(Dec 10 2020 at 04:25)</a>:</h4>
<p>yeah, on an avx512 target it would probably use them as well</p>



<a name="219430921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430921">(Dec 10 2020 at 04:25)</a>:</h4>
<p>we can use <code>#[cfg(target_feature)]</code> for that</p>



<a name="219430988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430988">(Dec 10 2020 at 04:27)</a>:</h4>
<p>ah, that might work better (though the layout of types depending on target features seems like a good way to accidentally shoot yourself in the foot)</p>



<a name="219430993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219430993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219430993">(Dec 10 2020 at 04:28)</a>:</h4>
<p>the "opaque" mask type explicitly has an unspecified layout</p>



<a name="219431044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219431044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219431044">(Dec 10 2020 at 04:28)</a>:</h4>
<p>if you need a particular layout you can opt into the trait (or use <code>Into</code> on the opaque mask to ensure a particular layout)</p>



<a name="219431049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219431049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219431049">(Dec 10 2020 at 04:29)</a>:</h4>
<p>yeah, though if it is de-facto defined, people will probably unintentionally depend on it.</p>



<a name="219431062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219431062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219431062">(Dec 10 2020 at 04:29)</a>:</h4>
<p>Maybe, but you can't screw that up without <code>unsafe</code>, and we're providing safe ways of doing it, so I think that's unsound</p>



<a name="219431114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219431114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219431114">(Dec 10 2020 at 04:30)</a>:</h4>
<p>you can transmute a fat pointer but I don't think the layout is actually specified, even though it probably has never changed?</p>



<a name="219431140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219431140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219431140">(Dec 10 2020 at 04:30)</a>:</h4>
<p>I was thinking more of how copying a <code>i1x32</code> is quite cheap, but a <code>m32x32</code> is waay more expensive.</p>



<a name="219431155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219431155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219431155">(Dec 10 2020 at 04:31)</a>:</h4>
<p>since it is 32x larger</p>



<a name="219431161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219431161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219431161">(Dec 10 2020 at 04:31)</a>:</h4>
<p>right but the rest of the ops will be way slower except on avx512 or risc-v or similar</p>



<a name="219431219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219431219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219431219">(Dec 10 2020 at 04:32)</a>:</h4>
<p>I guess my point is we're going to pick the default to be what's usually the best, but provide access to both on all platforms so you can do whatever you need to do</p>



<a name="219431227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219431227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219431227">(Dec 10 2020 at 04:33)</a>:</h4>
<p>yup, sounds good!</p>



<a name="219431251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219431251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219431251">(Dec 10 2020 at 04:33)</a>:</h4>
<p>I think we long ago admitted that you will absolutely be able to generate slow code, we're just trying to make it as easy as possible to make it fast</p>



<a name="219543365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219543365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219543365">(Dec 10 2020 at 22:31)</a>:</h4>
<p>Any ideas why masks use signed integers rather than unsigned?  I figure u8 is probably the best type for bit vector masks, but not sure</p>



<a name="219543527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219543527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219543527">(Dec 10 2020 at 22:32)</a>:</h4>
<p>i think because llvm internals are all signed ints</p>



<a name="219543542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219543542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219543542">(Dec 10 2020 at 22:32)</a>:</h4>
<p>just a quirk</p>



<a name="219543577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219543577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219543577">(Dec 10 2020 at 22:33)</a>:</h4>
<p>That seems reasonable</p>



<a name="219545361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219545361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219545361">(Dec 10 2020 at 22:52)</a>:</h4>
<p>LLVM's integer types are neither signed nor unsigned; only the operators on them are.</p>



<a name="219545497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219545497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219545497">(Dec 10 2020 at 22:54)</a>:</h4>
<p>An 8-bit mask that's either <code>00000000</code> or <code>11111111</code> is easier considered as signed so it's either <code>0</code> or <code>-1</code>, so that might be why they were used as signed.</p>



<a name="219550083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219550083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219550083">(Dec 10 2020 at 23:50)</a>:</h4>
<p>bitmasks might be better as <code>u1xN</code> rather than <code>i1xN</code> since that matches <code>bool</code> better</p>



<a name="219550210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219550210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219550210">(Dec 10 2020 at 23:52)</a>:</h4>
<p>I think I determined yesterday it will almost definitely be implemented on top of u8 vectors since element alignment is unambiguous, and it gives a handy way of doing other ops</p>



<a name="219550326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219550326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219550326">(Dec 10 2020 at 23:54)</a>:</h4>
<p>LLVM doesn't seem to like i1 vectors in function signatures</p>



<a name="219550998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/219550998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#219550998">(Dec 11 2020 at 00:03)</a>:</h4>
<p>I meant as the user-visible type</p>



<a name="226106298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/226106298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Henri Sivonen <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#226106298">(Feb 12 2021 at 07:53)</a>:</h4>
<p>The docs say that the layout of <code>Mask8</code> is unspecified. Why? Isn't it rather the point of having specified-lane-width mask types that their layout is specified?</p>



<a name="226112056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/226112056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#226112056">(Feb 12 2021 at 09:05)</a>:</h4>
<p>oh, I should really review the cargo doc output when doing code review.</p>



<a name="226137504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/226137504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#226137504">(Feb 12 2021 at 13:40)</a>:</h4>
<p>The idea is that depending on architecture, a Mask8 might either be a SimdMask8 or a BitMask</p>



<a name="226320249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/226320249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#226320249">(Feb 14 2021 at 19:21)</a>:</h4>
<p>wow. <a href="https://twitter.com/NikolaiVazquez/status/1361024473760153600">https://twitter.com/NikolaiVazquez/status/1361024473760153600</a></p>
<div class="inline-preview-twitter"><div class="twitter-tweet"><a href="https://twitter.com/NikolaiVazquez/status/1361024473760153600"><img class="twitter-avatar" src="https://pbs.twimg.com/profile_images/1240202107699040258/A-4ZSEfi_normal.jpg"></a><p><a href="https://twitter.com/ekuber">@ekuber</a> All that &lt;&lt;&lt;&lt; trait-dependent type sizes <a href="https://t.co/BbwSJARzNd">https://github.com/nvzqz/impls#trait-dependent-type-sizes</a> <a href="https://t.co/NWDcx4PMj4">https://twitter.com/NikolaiVazquez/status/1361024473760153600/photo/1</a></p><span>- nikolai (@NikolaiVazquez)</span><div class="twitter-image"><a href="https://t.co/NWDcx4PMj4"><img src="https://pbs.twimg.com/media/EuNUaegXYA4f_vC.png:small"></a></div></div></div>



<a name="226320955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/226320955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#226320955">(Feb 14 2021 at 19:39)</a>:</h4>
<p>Wow.  That's awesome and horrific at the same time.</p>



<a name="226324309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/226324309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Miguel Raz Guzmán Macedo <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#226324309">(Feb 14 2021 at 20:54)</a>:</h4>
<p>yeah I can't read that rust <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<a name="226324315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Mask%20API/near/226324315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Miguel Raz Guzmán Macedo <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Mask.20API.html#226324315">(Feb 14 2021 at 20:54)</a>:</h4>
<p>Too much ancient knowledge.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>